package com.hs.srm.admin.modules.pricemanagement.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.pricemanagement.dao.NPRODistributeViewDao;
import com.hs.srm.admin.modules.pricemanagement.entity.NPRODistributeViewEntity;
import com.hs.srm.base.common.annotation.DataFilter;
import com.hs.srm.base.common.utils.QueryParam;
import com.hs.srm.common.utils.PageUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author ych
 * @date 2019年8月12日
 * 非生产性订单分配货源
 */
@Service("nproDistributeViewService")
public class NPRODistributeViewServiceImpl extends ServiceImpl<NPRODistributeViewDao, NPRODistributeViewEntity> implements NPRODistributeViewService {

    @Autowired
    NPRODistributeViewDao nproDistributeViewDao;

    /**
     * vendor_kind:0，正式供应商；1，临时供应商
     *
     * @param params
     * @return
     */
    @Override
    @DataFilter
    public PageUtils queryPage(Map<String, Object> params) {
        String vendorCode = (String) params.get("vendorCode");
        String vendorName = (String) params.get("vendorName");
        String materialDesc = (String) params.get("materialDesc");
        Page<NPRODistributeViewEntity> page = this.selectPage(
                new QueryParam<NPRODistributeViewEntity>(params).getPage(),
                new EntityWrapper<NPRODistributeViewEntity>()
                        .like(StringUtils.isNotBlank(vendorName), "vendor_name", vendorName)
                        .like(StringUtils.isNotBlank(materialDesc), "material_desc", materialDesc)
                        .eq(StringUtils.isNotBlank(vendorCode), "vendor_code", vendorCode));
        return new PageUtils(page);
    }

    /**
     * 样品订单货源分配价格查询，供应商包括正式和临时
     *
     * @param params
     * @return
     */
    @Override
    public PageUtils queryUnionPage(Map<String, Object> params) {
        Page<NPRODistributeViewEntity> page=new QueryParam<NPRODistributeViewEntity>(params).getPage();
        page.setRecords(nproDistributeViewDao.queryUnionPage(page, new EntityWrapper<>(), params));
        return new PageUtils(page);
    }
}
